/**
 * <p>Title: liteflow</p>
 * <p>Description: 轻量级的组件式流程框架</p>
 * @author Bryan.Zhang
 * @email weenyc31@163.com
 * @Date 2020/4/1
 */
package io.mft.flow.core.executable;

import java.util.List;

import io.mft.commons.exception.MFTException;
import io.mft.commons.function.ExecuteReturn;
import io.mft.flow.core.FlowExecutor;
import io.mft.flow.core.executable.drive.ChainConditionDriver;
import io.mft.flow.data.ChainContext;

public abstract class Condition {

	private FlowExecutor flowExecutor;
	private List<ConditionExecutable> nodeList;
	protected ChainConditionDriver chainConditionDriver;
	protected ChainCondition chainCondition;
	public Condition(ChainConditionDriver chainConditionDriver,List<ConditionExecutable> nodeList) {
		this.nodeList = nodeList;
		this.chainConditionDriver = chainConditionDriver;
	}
	public ChainConditionDriver chainConditionDriver() {
		return chainConditionDriver;
	}
	public List<ConditionExecutable> getNodeList() {
		return nodeList;
	}

	public void setNodeList(List<ConditionExecutable> nodeList) {
		this.nodeList = nodeList;
	}

	public ConditionExecutable first() {
		return nodeList.get(0);
	}

	public ConditionExecutable last() {
		return nodeList.get(nodeList.size() - 1);
	}
	
	public void setChainCondition(ChainCondition chainCondition) {
		this.chainCondition = chainCondition;
	}
	public abstract ConditionType conditionType();
	
	
	public abstract ExecuteReturn execute(ChainContext context) throws Exception;
	public void setFlowExecutor(FlowExecutor flowExecutor) {
		this.flowExecutor = flowExecutor;
	}
	public FlowExecutor getFlowExecutor() {
		if (flowExecutor==null) {
			throw new MFTException("未设置FlowExecutor");
		}
		return flowExecutor;
	}
}
